package edu.api.set_api;

import java.util.Objects;

public class Product implements Comparable<Product>{
    // 商品类
    private int id; // 商品编号
    private String name; // 名称
    private Float price; // 价格

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Product product = (Product) o;
        return id == product.id && Float.compare(product.price, price) == 0 && Objects.equals(name, product.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, price);
    }

    public Product(int id, String name, float price) {
        this.name = name;
        this.id = id;
        this.price = price;
    }

    public Product() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    // 这里是上面3个属性的setter/getter方法，这里省略
    public String toString() {
        return "商品编号：" + id + "，名称：" + name + "，价格：" + price;
    }

    /**
     * 定义排序规则
     * @param o
     * @return
     */
    @Override
    public int compareTo(Product o) {
        return o.price.compareTo(this.price);
    }
}
